package com.example.jnademo;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: zehao.song
 */
@RestController
@RequestMapping("test")
public class TestController {

    @RequestMapping("jna")
    public int jna() {
        Clibrary instance = Clibrary.INSTANCE;
        // 方法一
        int result = instance.add(10, 20);
        return result;
    }

    @RequestMapping("pirJna")
    public String pirJna(@RequestBody PirParam pirParam) {
        Clibrary2 instance = Clibrary2.INSTANCE;

        String host = pirParam.getHost() != null ? pirParam.getHost() : "192.168.1.101";
        int port = pirParam.getPort() != null ? pirParam.getPort() : 32011;
        int serviceId = pirParam.getServiceId() != null ? pirParam.getServiceId() : 1;
        String searchDataId = pirParam.getSearchDataId() != null ? pirParam.getSearchDataId() : "N010001";
        String merchantNo = pirParam.getMerchantNo() != null ? pirParam.getMerchantNo() : "M000001";
        String privateKey = pirParam.getPrivateKey() != null ? pirParam.getPrivateKey() : "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBALFZvbb2_FZIR8-vkQsBPinzRYDeBB6Ag6r0BJFuT4i6u2VF0VqanAnvNOY6VBp7n3hjNWClv1GQP1whhDzDt2hRVZbYWKpk5Ac_9-5U6hXoXYPtfyY-28VISVtI3gYbtH-KoVrvJewJgc_8hEdvp3cZd47Kldpyn3iUHaT8iINJAgMBAAECgYEAhraJEdK4R_3tdkeA4CAYjRr5v3JlJJov6Yojciidh1l4AOwwoybvwegOgZbqzZb7wiFxqTEdiyILzrqyzMlJpU4mJaGqA_rkIjz6KavaQHhL-jrqwpW1WuNtUdzensDe-MMSPx9bFxQXMizQjB-5oB0OUnNgBE52keY7n8eqmBECQQD9H3L7uIAaPxnVItaTbPEKxXJRVtkY-qpEwmV3bzn8mAwcsFNh0UhjVuUTzNNGt3Fo4xO1JCJbiJ9J8zYxaqoFAkEAs13ONXrg6yRP7UvR74kQDl5Z_db4QgZQUoKZDme9FQ8VDGnbdPwdFW9eTqc1dfqh0DRMLNsQurrrThOW8dvDdQJBAJfdfoc4MuOMaFtQA52ABz6HKAdVK_uoqO-IEoiN2ySJtPqhb-WIQv4W7GnswfXzqb9cPj6350Uzux4LJcCQVmECQA0C1vyGJ16nSaz6_QWVObbxHTIOr_-KGbWCh7vFxq-KYop9-09nImz1oS-vbW9bePVzdbsjQPlqqbsGLMLqoCkCQQCldBbCxMlHdGsstFihBFHWILbGrVYHjf2EKMsDzK20PmkvfED0IDPE8xzl-6WSa9VViDcswhN2-bFnT-5GXsqW";

        String result = instance.query(0, host, port, merchantNo, privateKey, serviceId, searchDataId);
        return result;
    }

    public static class PirParam {
        String host;
        Integer port;
        Integer serviceId;
        String searchDataId;
        String merchantNo;
        String privateKey;

        public PirParam(String host, Integer port, int serviceId, String searchDataId, String merchantNo, String privateKey) {
            this.host = host;
            this.port = port;
            this.serviceId = serviceId;
            this.searchDataId = searchDataId;
            this.merchantNo = merchantNo;
            this.privateKey = privateKey;
        }

        public String getHost() {
            return host;
        }

        public void setHost(String host) {
            this.host = host;
        }

        public Integer getPort() {
            return port;
        }

        public void setPort(Integer port) {
            this.port = port;
        }

        public Integer getServiceId() {
            return serviceId;
        }

        public void setServiceId(Integer serviceId) {
            this.serviceId = serviceId;
        }

        public String getSearchDataId() {
            return searchDataId;
        }

        public void setSearchDataId(String searchDataId) {
            this.searchDataId = searchDataId;
        }

        public String getMerchantNo() {
            return merchantNo;
        }

        public void setMerchantNo(String merchantNo) {
            this.merchantNo = merchantNo;
        }

        public String getPrivateKey() {
            return privateKey;
        }

        public void setPrivateKey(String privateKey) {
            this.privateKey = privateKey;
        }
    }

}
